{% extends "admin/base.html" %}

{% block content %}
<link rel="stylesheet" href="/static/impromptu.css" type="text/css" media="screen"/>
<script type="text/javascript" src="/static/js/jquery-impromptu.3.1.min.js"></script>
<script type="text/javascript">

$(document).ready(function(){
	function openLoanCalculatorPrompt(){
		
		var formstr = '<p>创建相册:</p>'+
			'<div class="field"><label for="intamount">相册名称</label><input type="text" name="albumName" id="albumName" value="" /></div>'+
			'<div class="field"><label for="intrate">相册描述</label><textarea name="description" id="desc"></textarea></div>';
			
		jqistates = {
			album: {
				html: formstr,
				focus: 1,
				buttons: { Submit: true ,Cancel: false},
				submit: function(v, m, f){
					var e = "";
					m.find('.errorBlock').hide('fast',function(){ jQuery(this).remove(); });
					if (v) {
						if(!f.albumName)
							e += "请输入相册名称!<br />";
						
						if (e == "") {
							jQuery.ajax({
								type: "POST",
								url:'/admin/save_album',
								data:{albumName:f.albumName,desc:f.description},
								success:function(response){}
							});
							return true;
						}else{
							jQuery('<div class="errorBlock" style="display: none;">'+ e +'</div>').prependTo(m).show('slow');
						}
						return false;
					}
					else return true;
				}
			}
		};
		$.prompt(jqistates);
	}

	$("#newalbum").click(openLoanCalculatorPrompt)
	
}); 


</script>
<div class="wrap">
 <h2>相册管理</h2>
 
	 <div class="metabox-holder">
	 	 <div class="postbox">
	 	 	<h3 class="hndle">相册</h3>
		 	 	<div class="inside">
		 	 	<div id="tools">
		 	 		<a href="">上传照片</a> | <a id="newalbum" href="#">新建相册</a>
		 	 	</div>
		 	 	
		 	 	<div class="picbox">
		 	 	{%if albums%}
		 	 		<ul class="picul">
		 	 			{%for album in albums %}
		 	 			<li>
		 	 				<div id="photo">
		 	 					<a href="/admin/album_detail?id={{album.id}}">
		 	 						<div></div>
		 	 					</a>
		 	 					<p>{{album.name}}</p>
		 	 					<p class="opreat">
		 	 						<span><a href="/admin/album/edit?id={{album.id}}">编辑</a></span>
		 	 						| <span><a href="/admin/album/delete?id={{album.id}}">删除</a></span>
		 	 					</p>
		 	 				</div>
		 	 			</li>
		 	 			{%endfor%}
		 	 			<div class="clear"></div>
		 	 		</ul>
		 	 	{%else%}
		 	 	 <p style="text-align:center;">你还没有上传相片</p>
		 	 	{%endif%}
		 	 	</div>
		 	 	</div>
	 	 </div>
 	</div>
</div>
{%endblock%}